//
//  DHS2_ProductInfo_DisCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/21.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_ProductInfo_DisCell.h"
#import "DHProductInfoCell.h"

@interface DHS2_ProductInfo_DisCell()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSDictionary *productDetailDic;

@end

@implementation DHS2_ProductInfo_DisCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHProductInfoCell" bundle:nil] forCellReuseIdentifier:kDHProductInfoCell];
}

- (void)updateCell:(NSDictionary *)dic{
    self.productDetailDic = dic;
    [self.tableView reloadData];
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[self.productDetailDic objectForKey:@"properties"] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 1) {
        NSArray *properties = [self.productDetailDic objectForKey:@"properties"];
        CGFloat height = 0;
        if (properties.count >= 2) {
            NSDictionary *dic = [properties objectAtIndex:1];
            NSString *vaule = [dic objectForKey:@"value"];
            CGFloat valueHeight = [vaule heightForFont:[UIFont systemFontOfSize:15] width:kScreenWidth - 84];
            height += valueHeight;
        }
        return height;
    }else{
        return 35;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHProductInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHProductInfoCell forIndexPath:indexPath];
    NSDictionary *dynamic_prop = [[self.productDetailDic objectForKey:@"properties"] objectAtIndex:indexPath.row];
    cell.keyLabel.text = [dynamic_prop objectForKey:@"key"];
    cell.valueLabel.text = [dynamic_prop objectForKey:@"value"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
